1. Field of the Invention
Apparatuses and methods consistent with the present invention relate to data processing for a flash memory, and more particularly, to data processing for a flash memory, which can easily determine whether data stored in the flash memory is valid.
2. Description of the Related Art
In general, home appliances, communications devices, and embedded systems, such as set-top boxes, use non-volatile memories as storage devices for storing and processing data.
Flash memories are one type of non-volatile memory, in which data can be electrically erased and overwritten. Flash memories are suitable for portable devices because they consume less power than magnetic disk memory-based storage mediums, are as accessible as hard disks, and are compact-sized.
Due to the hardware characteristics of flash memories, data recorded on a flash memory should be erased before data is overwritten on the flash memory.
A unit in which data is recorded on a flash memory may differ from a unit in which data is erased from the flash memory, which may result in deterioration of the performance of the flash memory.
In order to prevent the performance of the flash memory from deteriorating for this reason, logical addresses and physical addresses have been suggested.
Here, logical addresses are virtual addresses specified by a user when executing a data operation on the flash memory with the use of a program. By comparison, physical addresses are actual addresses referenced when executing the data operation on the flash memory.
Flash memory is generally classified into either a small block flash memory or a large block flash memory. In a small block flash memory, a logical operation unit is equal to a physical operation unit, whereas in a large block flash memory, a logical operation unit is smaller than a physical operation unit.
FIGS. 1A and 1B are schematic diagrams illustrating a small block flash memory and a large block flash memory, respectively.
Referring to FIG. 1A, logical computations of the small block flash memory are performed in units of a sector 11, and physical computations of the small block flash memory are performed in units of a page 12, which is as large as sector 11.
Meanwhile, as shown in FIG. 1B, logical computations of the large block flash memory are performed in units of a sector 21, and physical computations of the large block flash memory are performed in units of a page 22, which is comprised of at least one sector 21.
A flash memory-based system may unexpectedly suffer from frequent power interruptions due to its characteristics. Therefore, the flash memory-based system needs a function of recovering data which is damaged or lost due to a power interruption.
Data write and erase operations for a flash memory will now be described in detail. If power is cut off in the process of writing data to a flash memory, only part of the data is successfully written to the flash memory. If power is cut off in the process of erasing data from a flash memory, only part of the data is successfully erased from the flash memory.
Therefore, a variety of methods of determining whether data stored in a flash memory is valid if power is cut off in the process of performing a data operation, such as a write operation or an erase operation, on the flash memory have been suggested.
FIG. 2 is a flowchart illustrating a conventional method of writing data to a flash memory.
Referring to FIG. 2, in operation S10, it is determined whether a predetermined sector of a flash memory is a recordable sector. In other words, it is determined whether data has already been written to the predetermined sector of the flash memory, the result of which is later used to decide whether to perform a write operation or an erase operation.
If the predetermined sector of the flash memory is determined to be a recordable sector in operation S10, a write operation is performed on the predetermined sector of the flash memory, in operation S20. In operation S30, a first mark value is recorded in a predetermined index area corresponding to the predetermined sector of the flash memory.
In detail, as shown in FIG. 3, a block 34 of a flash memory comprises a plurality of pages 33, and each of the pages 33 comprises a data area 31 and an index area 32. The index area 32 comprises a first index area 32a, which indicates how much of a write operation currently being performed on the flash memory has been completed and a second index area 32b, which indicates how much of an erase operation currently being performed on the flash memory has been completed. The first mark value may be recorded in the first index area 32a while a write operation is performed on the data area 31.
In a case where the data area 31 comprises a plurality of sectors as illustrated in FIG. 4, the first index area 32a comprises as many first sub-index areas as the number of sectors constituting the data area 31. On the other hand, the second index area 32b, unlike the first index area 32a, corresponds to a block instead of a sector.
If the write operation is completed in operation S40, a second mark value is recorded in the first index area 32a to indicate that the write operation is completed in operation S50.
For example, when a write operation begins, a first mark value of 0xF0 is recorded in the first index area 32a. When the write operation ends, a second mark value of 0x00 is recorded in the first index area 32a. 
If the predetermined sector of the flash memory is determined not to be a recordable sector in operation S10, an erase operation is performed on the predetermined sector of the flash memory in operation S60. In operation S70, a third mark value is recorded in the second index area 32b to indicate that the erase operation is completed. The third mark value may be identical to the second mark value recorded in the first index area 32a, i.e., 0x00.
If an initial value of, for example, 0xFF is recorded in both the first index area 32a and the second index area 32b, the predetermined sector of the flash memory may be determined to be a recordable sector in operation S10. Alternatively, if an initial value of 0xFF is recorded in the data area 31, the predetermined sector of the flash memory may be determined to be a recordable sector in operation S10. In detail, in a case where an erase operation is performed on the predetermined sector of the flash memory, all of the bits of the mark values recorded in the first index area 32a and the second index area 32b are changed to a logic value of 1. In this case, the predetermined sector of the flash memory may be determined to be a recordable sector if an initial value of 0xFF is recorded in the data area 31.
FIG. 5 is a flowchart illustrating a conventional method of determining whether data written to a flash memory using the method as illustrated in FIG. 2 is valid.
Referring to FIG. 5, in operation S80, it is determined whether a second mark value and a third mark value recorded in the first index area 32a and the second index area 32b, respectively, are valid.
In detail, if 0x00 is recorded in the first index area 32a and the second index area 32b as the second mark value and the third mark value, the second and third mark values are determined to be valid.
If the second and third mark values are determined to be valid, the data recorded in a sector corresponding to the first and second index areas 32a and 32b is determined to be valid in operation S90. If the second and third mark values are determined not to be valid, the data recorded in the sector corresponding to the first and second index areas 32a and 32b is determined to be invalid in operation S100.
In the conventional method as illustrated in FIG. 5, it is necessary to record a first mark value and a second mark value in the first index area 32a in the process of writing data to the data area 31. However, the recording of the first and second mark values in the first index area 32a may deteriorate the performance of a flash memory.
In addition, if power is cut off in the process of performing an erase operation on the flash memory, data stored in the data area 31 may be successfully erased, but the mark values stored in the first and second index areas 32a and 32b may not be erased. In this case, the data stored in the data area 31 may be mistakenly determined to be valid because of the mark values still stored in the first and second index areas 32a and 32b. In other words, if power is cut off in the process of performing an erase operation on the data area 31 as illustrated in FIG. 6A, data stored in the data area 31 becomes invalid as illustrated in FIG. 6B, but mark values (0x00) stored in the first and second index areas 32a and 32b still indicate that the data stored in the data area 31 is valid. Thus, the data stored in the data area 31 may be mistakenly determined to be valid because of the mark values recorded in the first and second index areas 32a and 32b. 
Korean Patent Laid-Open Publication No. 2005-0040120 discloses a method of writing data to a flash-type memory of an electronic module, which includes: associating at least two physical areas of the flash-type memory, which are called mirror areas, with a logical area; and programming data written to the logical area in one of the mirror areas while performing a write operation on the logical area. This method is useful for optimizing the time required to write data to a memory. However, in this method, it is difficult to determine whether data written to a memory is valid especially when an unexpected event, such as the power being cut off from the memory in the process of performing a data operation on the memory, occurs.